package cn.edu.sdjzu.xg.eagle.service.impl;

import cn.edu.sdjzu.xg.eagle.entities.CommunityActivity;
import cn.edu.sdjzu.xg.eagle.mapper.CommunityActivityMapper;
import cn.edu.sdjzu.xg.eagle.service.inface.CommunityActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommunityActivityImpl implements CommunityActivityService {

    @Autowired
    private CommunityActivityMapper communityActivityMapper;

    @Override
    public String addCommunityActivity(CommunityActivity communityActivity) {
        try {
            if (communityActivityMapper.addCommunityActivity(communityActivity)) {
                return "添加活动成功";
            }
            return "添加活动失败";
        } catch (Exception e) {
            e.printStackTrace();
            return "添加活动异常: " + e.getMessage();
        }
    }
    @Override
    public String updateCommunityActivity(CommunityActivity communityActivity) {
        try {
            if (communityActivityMapper.updateCommunityActivity(communityActivity)) {
                return "更新活动成功";
            }
            return "更新活动失败";
        } catch (Exception e) {
            e.printStackTrace();
            return "更新活动异常: " + e.getMessage();
        }
    }
    @Override
    public String deleteCommunityActivity(String activityID) {
        try {
            if (communityActivityMapper.deleteCommunityActivity(activityID)) {
                return "删除活动成功";
            }
            return "删除活动失败";
        } catch (Exception e) {
            e.printStackTrace();
            return "删除活动异常: " + e.getMessage();
        }
    }


    @Override
    public CommunityActivity findCommunityActivityByActivityID(String activityID) {
        try {
            return communityActivityMapper.findCommunityActivityByActivityID(activityID);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public List<CommunityActivity> findCommunityActivitys() {
        try {
            return communityActivityMapper.findCommunityActivitys();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}